﻿using System;
using System.IO;

namespace Flagwind.Utilities
{
	public class DeploymentContext
	{
		#region 成员字段

		private Deployer _deployer;
		private DeploymentCounter _counter;
		private string _destinationDirectory;
		private Flagwind.Options.Profiles.Profile _deploymentFile;

		#endregion

		#region 公共属性

		public Deployer Deployer
		{
			get
			{
				return _deployer;
			}
		}

		public DeploymentCounter Counter
		{
			get
			{
				return _counter;
			}
		}

		public string DestinationDirectory
		{
			get
			{
				return _destinationDirectory;
			}
		}

		public Flagwind.Options.Profiles.Profile DeploymentFile
		{
			get
			{
				return _deploymentFile;
			}
		}

		public string SourceDirectory
		{
			get
			{
				return Path.GetDirectoryName(this.DeploymentFile.FilePath);
			}
		}

		#endregion

		#region 构造方法

		public DeploymentContext(Deployer deployer, Flagwind.Options.Profiles.Profile deploymentFile, string destinationDirectory)
		{
			if(deployer == null)
				throw new ArgumentNullException(nameof(deployer));

			if(deploymentFile == null)
				throw new ArgumentNullException(nameof(deploymentFile));

			if(string.IsNullOrWhiteSpace(destinationDirectory))
				throw new ArgumentNullException(nameof(destinationDirectory));

			_deployer = deployer;
			_deploymentFile = deploymentFile;
			_destinationDirectory = destinationDirectory;
			_counter = new DeploymentCounter();
		}

		#endregion
	}
}